#
# Copyright (C) 1996,1997 Michael R. Elkins <me@cs.hmc.edu>
#
#     This program is free software; you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation; either version 2 of the License, or
#     (at your option) any later version.
#
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.
#
#     You should have received a copy of the GNU General Public License
#     along with this program; if not, write to the Free Software
#     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

SHELL=/bin/sh
VERSION=@VERSION@

prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
libdir=@libdir@
mandir=@mandir@
sharedir=@sharedir@
srcdir=@srcdir@
VPATH=@srcdir@
@SET_MAKE@

INSTALL=@INSTALL@
CC=@CC@
XCPPFLAGS=-I. @CPPFLAGS@
CFLAGS=@CFLAGS@ -DSHAREDIR=\"$(sharedir)\" $(XCPPFLAGS)
LDFLAGS=@LDFLAGS@
LIBS=@LIBS@
OPS=@OPS@
OBJS=	addrbook.o alias.o attach.o bind.o browser.o buffy.o color.o \
        commands.o complete.o compose.o copy.o curs_lib.o curs_main.o date.o \
	edit.o enter.o flags.o init.o filter.o from.o getdomain.o \
	handler.o hdrline.o headers.o help.o hook.o keymap.o lib.o main.o \
	mbox.o menu.o mh.o mx.o pager.o parse.o pattern.o \
	postpone.o print.o recvattach.o rfc822.o \
	rfc1524.o rfc2047.o send.o sendlib.o signal.o sort.o \
	status.o system.o thread.o @LIBOBJS@
CLEANFILES=mutt *.o *~ *.rej *.orig

# kill these files when making new export distributions
NONEXPORT=pgp.c pgp.h pgpinvoke.c pgpkey.c pgppubring.c sha.h sha1dgst.c sha_locl.h \
	OPS.PGP doc/pgp-Notes.txt

all: mutt

mutt: keymap_defs.h $(OBJS) $(REGEX)
	$(CC) -o mutt $(OBJS) $(REGEX) $(LDFLAGS) $(LIBS)

keymap_defs.h: Makefile $(OPS)
	rm -f keymap_defs.h
	$(srcdir)/gen_defs $(OPS) > keymap_defs.h

install: mutt
	$(srcdir)/mkinstalldirs $(bindir)
	-mv -f $(bindir)/mutt $(bindir)/mutt.old
	$(INSTALL) @MUTT_GROUP@ -m @MUTT_PERMISSION@ mutt $(bindir)
	$(srcdir)/mkinstalldirs $(mandir)/man1
	$(INSTALL) -m 644 $(srcdir)/doc/mutt.man $(mandir)/man1/mutt.1
	-if [ ! -f $(sharedir)/Muttrc ]; then \
		$(srcdir)/mkinstalldirs $(sharedir); \
		$(INSTALL) -m 644 $(srcdir)/Muttrc $(sharedir); \
	fi
	-if [ ! -f $(sharedir)/mime.types ]; then \
		$(INSTALL) -m 644 $(srcdir)/mime.types $(sharedir); \
	fi

uninstall:
	rm -f $(bindir)/mutt $(sharedir)/Muttrc $(mandir)/man1/mutt.1

$(srcdir)/configure: $(srcdir)/configure.in
	autoconf

Makefile: $(srcdir)/Makefile.in
	./config.status

config.h.in: $(srcdir)/acconfig.h
	autoheader

config.h: $(srcdir)/config.h.in
	./config.status

tags:
	(cd $(srcdir) && ctags *.[ch])

dep: Makefile
	mv Makefile Makefile.bak
	awk -f $(srcdir)/depend.awk < Makefile.bak > Makefile
	echo '# DO NOT REMOVE THIS LINE' >> Makefile
	$(CC) -MM $(XCPPFLAGS) $(srcdir)/*.c >> Makefile

clean-real:
	(cd $(srcdir) && rm -f $(CLEANFILES))
	(cd $(srcdir)/doc && $(MAKE) $@)

clean: clean-real
	rm -f $(CLEANFILES)

distclean: clean-real
	(cd $(srcdir) && rm -f config.cache config.log config.status \
		Makefile config.h keymap_defs.h tags)

# make export version
usdist: distclean
	rm -rf /tmp/mutt-$(VERSION)
	(cd .. && cp -r mutt-$(VERSION) /tmp)
	for i in `grep _PGPPATH $(srcdir)/*.[ch] | sed 's/^\([^:]*\).*/\1/' | grep -v '/main\.c' | grep -v '/pgp'` ; do \
		target=`basename $$i` ; \
		$(srcdir)/reap.pl _PGPPATH < $(srcdir)/$$target > /tmp/mutt-$(VERSION)/$$target; \
	done
	for i in $(NONEXPORT); do \
		rm -f /tmp/mutt-$(VERSION)/$$i; \
	done
	(cd /tmp && tar cfz mutt-$(VERSION).tar.gz mutt-$(VERSION))
	rm -rf /tmp/mutt-$(VERSION)

# make international distribution
dist: distclean
	(cd $(srcdir)/.. && tar cfz mutt-$(VERSION)i.tar.gz mutt-$(VERSION)i)

rx/librx.a:
	(cd rx && $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)")

